#!/usr/bin/env python
# Author: iris and jeff

PKG = 'sound_localization'
NAME = 'noise_maker'

import roslib; roslib.load_manifest(PKG)
import rospy

from geometry_msgs.msg import Point
from nav_msgs.msg import Odometry


class NoiseMaker():
    def __init__(self):
        rospy.init_node(NAME, anonymous=True)
        rospy.Subscriber("/erratic_odometry/odom", Odometry, self.odom_callback)


    def odom_callback(self, data):
        try:
            pub = rospy.Publisher('/sound_localization/audio_packet', Point, latch=True)
            pub.publish(x=data.pose.pose.position.x, \
                        y=data.pose.pose.position.y, \
                        z=data.pose.pose.position.z)
            print "noise_maker: publishing and latching message for 3.0 seconds"
            rospy.sleep(rospy.Duration(3))
            pub.unregister()
            rospy.signal_shutdown('Done its job.')
        except rospy.ServiceException, e:
            print "Reply failed: %s" % e


if __name__ == '__main__':
    try:
        st = NoiseMaker()
        rospy.spin()
    except rospy.ROSInterruptException:
        pass
